﻿Public Class GEstMaterielNeuf
    Dim i As Integer = 0
    Dim tva As String
    Dim macnx As New PPE3.ClassMySqlConnect("853339_depanneur", "071064")


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = FrmStart
        Me.Left = 0
        Me.Top = 0

        macnx.Se_Connecter_MySqlServer()

        dgCAl.DataSource = Nothing
        macnx.viderVue("Toutm")
        dgCAl.DataSource = macnx.Executer_Requete_Select("select * from calcule ", "Toutm")

        macnx.Se_Deconnecter_MySqlServer()

        TxtCategorie.Enabled = False
        TxtCategorie.BackColor = Color.White

        TxtDesignation.Enabled = False
        TxtDesignation.BackColor = Color.White

        Txtprix.Enabled = False
        Txtprix.BackColor = Color.White

        TxtReference.Enabled = False
        TxtReference.BackColor = Color.White

    End Sub

    Private Sub rafraichir()

        macnx.Se_Connecter_MySqlServer()

        DgMN.DataSource = Nothing
        macnx.viderVue("Toutmateriel")
        DgMN.DataSource = macnx.Executer_Requete_Select("select * from materielneuf where ReferenceMaterielNeuf LIKE '" & TextBox1.Text & "'", "Toutmateriel")

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        rafraichir()

        If TextBox1.Text <> "" Then
            TxtReference.Text = DgMN.Rows(0).Cells(1).Value
            TxtDesignation.Text = DgMN.Rows(0).Cells(2).Value
            TxtCategorie.Text = DgMN.Rows(0).Cells(3).Value
            Txtprix.Text = DgMN.Rows(0).Cells(4).Value
        End If

        Dim Ok As Boolean = False

        If Txtprix.Text <> "" Then

            While Ok = False

                Dim Com As String = dgCAl.Rows(i).Cells(1).Value.ToString()

                If CDec(Txtprix.Text) < CDec(Com) Then
                    i = i + 1
                Else
                    Ok = True
                    tva = macnx.ExecuteScalar("SELECT tva FROM tva WHERE idtva = 1")
                    Dim multi As String = CDec(Txtprix.Text) * dgCAl.Rows(i).Cells(2).Value.ToString * tva

                    Txtprix.Text = multi
                    i = 0

                End If

            End While

        Else
            Txtprix.Text = ""
        End If
    End Sub


    'Private Sub DgMN_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgMN.CellClick
    '    TextBox2.Text = DgMN.CurrentRow.Cells(4).Value()
    'End Sub

    'Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    '    Dim a As Integer = 1
    '    Dim b As Integer = 2
    '    Dim c As Integer = 3
    '    Dim d As Integer = 4
    '    Dim f As Integer = 5
    '    Dim g As Integer = 6
    '    Dim h As Integer = 7
    '    Dim result
    '    Dim tva As String = connection.tva()
    '    If TextBox2.Text = "" Then
    '        TextBox3.Text = ""

    '    ElseIf TextBox2.Text > 900 Then
    '        connection.test(g, TextBox2, TextBox3)
    '        'connection.MaRequete = "select TVA from tva where ( idCalcule= '" & g & "' )"
    '        'connection.MaCommandeSpecialRequete.CommandText = connection.MaRequete
    '        'connection.MonRemplisseur.SelectCommand = connection.MaCommandeSpecialRequete

    '        'Dim mult As String = connection.Mult("Multiplie", "tva", g)
    '        'Dim tva As String = connection.tva("TVA", "tva", a)
    '        'result = ((TextBox2.Text * mult) * tva)

    '        'TextBox3.Text = result

    '    ElseIf TextBox2.Text <= 900 And TextBox2.Text > 80 Then
    '        connection.test(h, TextBox2, TextBox3)
    '        'connection.MaRequete = "select TVA from tva where ( idCalcule= '" & h & "' )"
    '        'connection.MaCommandeSpecialRequete.CommandText = connection.MaRequete
    '        'connection.MonRemplisseur.SelectCommand = connection.MaCommandeSpecialRequete


    '        'Dim mult As String = connection.Mult("Multiplie", "tva", g)
    '        'Dim tva As String = connection.tva("TVA", "tva", a)
    '        'result = ((TextBox2.Text * mult) * tva)
    '        'result = TextBox2.Text * mult

    '        'TextBox3.Text = result

    '    ElseIf TextBox2.Text <= 80 And TextBox2.Text > 30 Then
    '        connection.test(f, TextBox2, TextBox3)
    '        'connection.MaRequete = "select TVA from tva where ( idCalcule= '" & f & "' )"
    '        'connection.MaCommandeSpecialRequete.CommandText = connection.MaRequete
    '        'connection.MonRemplisseur.SelectCommand = connection.MaCommandeSpecialRequete


    '        'Dim mult As String = connection.Mult("Multiplie", "tva", g)
    '        'Dim tva As String = connection.tva("TVA", "tva", a)
    '        'result = ((TextBox2.Text * mult) * tva)

    '        'TextBox3.Text = result

    '    ElseIf TextBox2.Text <= 30 And TextBox2.Text > 20 Then
    '        connection.test(d, TextBox2, TextBox3)
    '        'connection.MaRequete = "select TVA from tva where ( idCalcule= '" & d & "' )"
    '        'connection.MaCommandeSpecialRequete.CommandText = connection.MaRequete
    '        'connection.MonRemplisseur.SelectCommand = connection.MaCommandeSpecialRequete


    '        'Dim mult As String = connection.Mult("Multiplie", "tva", g)
    '        'Dim tva As String = connection.tva("TVA", "tva", a)
    '        'result = ((TextBox2.Text * mult) * tva)

    '        'TextBox3.Text = result

    '    ElseIf TextBox2.Text <= 20 And TextBox2.Text > 10 Then
    '        connection.test(c, TextBox2, TextBox3)
    '        'connection.MaRequete = "select TVA from tva where ( idCalcule= '" & c & "' )"
    '        'connection.MaCommandeSpecialRequete.CommandText = connection.MaRequete
    '        'connection.MonRemplisseur.SelectCommand = connection.MaCommandeSpecialRequete


    '        'Dim mult As String = connection.Mult("Multiplie", "tva", g)
    '        'Dim tva As String = connection.tva("TVA", "tva", a)
    '        'result = ((TextBox2.Text * mult) * tva)

    '        'TextBox3.Text = result

    '    ElseIf TextBox2.Text <= 10 And TextBox2.Text > 5 Then
    '        connection.test(b, TextBox2, TextBox3)
    '        'connection.MaRequete = "select TVA from tva where ( idCalcule= '" & b & "' )"
    '        'connection.MaCommandeSpecialRequete.CommandText = connection.MaRequete
    '        'connection.MonRemplisseur.SelectCommand = connection.MaCommandeSpecialRequete


    '        'Dim mult As String = connection.Mult("Multiplie", "tva", g)
    '        'Dim tva As String = connection.tva("TVA", "tva", a)
    '        'result = ((TextBox2.Text * mult) * tva)

    '        'TextBox3.Text = result

    '    ElseIf TextBox2.Text <= 5 And TextBox2.Text >= 0 Then
    '        connection.test(a, TextBox2, TextBox3)
    '        'connection.MaRequete = "select TVA from tva where ( idCalcule= '" & a & "' )"
    '        'connection.MaCommandeSpecialRequete.CommandText = connection.MaRequete
    '        'connection.MonRemplisseur.SelectCommand = connection.MaCommandeSpecialRequete


    '        'Dim mult As String = connection.Mult("Multiplie", "tva", a)
    '        'Dim tva As String = connection.tva("TVA", "tva", a)
    '        'result = ((TextBox2.Text * mult) * tva)

    '        'TextBox3.Text = result

    '    End If

    'End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim gest As New GEstTVA
        gest.Show()
    End Sub

    'Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged



    '    Dim Ok As Boolean = False
    '    If DgMN.Rows(i).Cells(2).Value.ToString <> "" Then


    '        While Ok = False

    '            Dim Com As String = dgCAl.Rows(i).Cells(1).Value.ToString()

    '            If CDec(TextBox2.Text) < CDec(Com) Then
    '                i = i + 1
    '            Else
    '                Ok = True
    '                tva = connection.tva("TVA", "tva")
    '                Dim multi As String = CDec(TextBox2.Text) * dgCAl.Rows(i).Cells(2).Value.ToString * tva

    '                Txtprix.Text = multi
    '                i = 0
    '            End If

    '        End While

    '    Else
    '        Txtprix.Text = ""
    '    End If




    'End Sub


End Class
